package com.post.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;
import com.post.pageModel.Shuangchuang;
import com.post.pageModel.Json;
import com.post.service.ShuangchuangServiceI;

@Action(value = "shuangchuangAction", results = {
		@Result(name = "shuangchuangManager", location = "/busi/shuangchuang/shuangchuangManager.jsp"),
		@Result(name = "shuangchuangAdd", location = "/busi/shuangchuang/shuangchuangAdd.jsp"),
		@Result(name = "shuangchuangEdit", location = "/busi/shuangchuang/shuangchuangEdit.jsp")
		})
public class ShuangchuangAction extends BaseAction implements ModelDriven<Shuangchuang> {

	private Shuangchuang shuangchuang = new Shuangchuang();
	private ShuangchuangServiceI shuangchuangService;

	public ShuangchuangServiceI getShuangchuangService() {
		return shuangchuangService;
	}

	@Autowired
	public void setShuangchuangService(ShuangchuangServiceI shuangchuangService) {
		this.shuangchuangService = shuangchuangService;
	}

	@Override
	public Shuangchuang getModel() {
		return shuangchuang;
	}

	public String shuangchuangManager() {
		return "shuangchuangManager";
	}

	public String shuangchuangAdd() {
		return "shuangchuangAdd";
	}

	public String shuangchuangEdit() {
		return "shuangchuangEdit";
	}

	public void do_datagrid() {
		super.writeJsonDate(shuangchuangService.datagrid(shuangchuang));
	}

	public void add() {
		Json j = new Json();
		try {
			shuangchuangService.add(shuangchuang);
			j.setSuccess(true);
			j.setMsg("添加成功！");
		} catch (Exception e) {
			j.setMsg("添加失败！");
		}
		super.writeJson(j);
	}

	public void edit() {
		Json j = new Json();
		try {
			shuangchuangService.edit(shuangchuang);
			j.setSuccess(true);
			j.setMsg("编辑成功！");
		} catch (Exception e) {
			j.setMsg("编辑失败！");
		}
		super.writeJson(j);
	}

	public void delete() {
		Json j = new Json();
		shuangchuangService.delete(shuangchuang);
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void finish() {
		Json j = new Json();
		shuangchuangService.finish(shuangchuang);
		j.setSuccess(true);
		j.setMsg("操作成功！");
		super.writeJson(j);
	}
	
	public void do_combobox() {
		super.writeJson(shuangchuangService.combobox());
	}
	

}